﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MongoDB.Driver;
using MongoDB.Bson;
using MongoDB.Driver.Builders;
using MongoDB.Driver.Linq;

namespace ProductCatalog.WebApi.DataLayer
{
    public static class MongoHelper
    {
        private const string baseJson = @"{{
    query: [
        {0}
    ]
}}";

        public static BsonDocument[] ParseToBsonDocumentArray(string json)
        {
            var parsableJson = string.Format(baseJson, json);
            var queryDoc = BsonDocument.Parse(parsableJson);
            var bsondocArray = queryDoc["query"].AsBsonArray;
            var docArray = bsondocArray.Select(i => i.AsBsonDocument)
                .ToArray();

            return docArray;
        }
    }
}